# -*- coding: utf-8 -*-
# @Time    : 2020/2/6 13:23
# @Author  : Weymouth
# @Email   : 261229090@qq.com
# @File    : 递归函数.py
# @Software: PyCharm
# ---------------------------------------------------

#循环
# def fat(n):
#     ret = 1
#     for i in range(1, n+1):
#         ret = ret*i
#     return ret
# print(fat(5))

#递归
# def fact(n):
#     if n == 1:
#         return 1
#
#     return n*fact(n-1)
# print(fact(5))

#关于递归:
#1.调用自身函数
#2.有一个结束条件
#3.但凡是递归可以写的循环，循环都可以做。
#递归的效率在很多时候会很低，

#斐波那契数列
# def fibo(n):
#     before = 0
#     after = 1
#     for i in range(n-1):
#         ret = before + after
#         before = after
#         after = ret
#     return ret
# print(fibo(3))

# def fibo(n):
#     if n==1:
#         return 0
#     if n==2:
#         return 1
#     return fibo(n-1)+fibo(n-2)
# print(fibo(8))

def fibo(n):
    if n == 0 or n == 1:
        return n
    return fibo(n-1)+fibo(n-2)
print(fibo(8))